{extend name="public:layout" /}

{block name="title"}
    <title>{:site('siteName')}-接单列表</title>
{/block}

{block name="css"}
    <style>
        .layui-table td, .layui-table th{padding:5px 2px;}
        .sell-tab { height: 40px; border-bottom: 1px solid #e2e2e2 }
        .sell-tab li { width: 50%; float: left; text-align: center; line-height: 40px; }
        .sell-tab .this { color: #009688; border-bottom: 3px solid #5FB878; margin-bottom: -3px;}
    </style>
{/block}

{block name="content"}
    <ul class="sell-tab">
        <li class="this">接单列表</li>
        <li>
            <a href="/recharge/myOrders">我的接单</a>
        </li>
    </ul>
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" style="width:100%;margin:0;">
        <div class="layui-tab-content">
            <!--收入明细-->
            <div class="layui-tab-item layui-show">
                <table class="layui-table">
                    <colgroup>
                        <col width="150">
                        <col width="150">
                        <col width="150">
                        <col width="200">
                        <col>
                    </colgroup>
                    <thead>
                        <tr>
                            <th>挂售时间</th>
                            <th>金额</th>
                            <th>状态</th>
                            <th>操作</th></tr>
                    </thead>
                    <tbody>
                        {volist name="list" id="v"}
                            <tr>
                                <td>{:date('Y-m-d',$v['time'])}</td>
                                <td>{$v['money']}</td>
                                <td>等待接单</td>
                                <td>
                                    <button class="layui-btn layui-btn-mini layui-btn-main add_order" sell_id="{$v.id}">接单</button>
                                </td>
                            </tr>
                        {/volist}
                    </tbody>
                </table>
                <div class="page" style="text-align: center;">
                    <button onclick="location.reload();" style="width: 100%;" class="layui-btn layui-btn-primary">刷新挂售</button>
                </div>
            </div>
        </div>
    </div>
    
    <div style="width:100%;height:50px;"></div>
{/block}

{block name="script"}
    <script type="text/javascript">
        layui.use(['form','layer'], function(){
            var $ = layui.jquery;
            var form = layui.form();
            var layer = layui.layer;
            //接单
            $('.add_order').click(function() {
                var sell_id = $(this).attr('sell_id');
                checkPwd(function(pwd){
                    layer.confirm('接单成功后取消订单或超时未支付将扣除违约金，确定接单？', {
                        btn: ['确定', '取消'],
                        icon: 3
                    }, function(index) {
                        layer.close(index);
                        $.post('{:url("index/sell/addOrder")}', {id: sell_id,pwd:pwd}, function(res) {
                            if(res.success == 1){
                                layer.msg(res.msg, {
                                    time: 1000
                                }, function() {
                                    location.href = '/recharge/myOrders.html';
                                });
                            }else{
                                layer.msg(res.msg);
                            }
                        });
                    });
                });
                return false;
            });
            
        });
    </script>
{/block}